package javaJob.exercise.primary.array;


public class primary2 {
    public static void main(String[] args) {
        int[] prices={7,1,5,3,6,4};
        int[] prices1={1,2,3,4,5};
        int[] prices2={7,6,4,3,1};
        if (5<prices.length){
            System.out.println("aaa");
        }

        System.out.println(prices.length);

        int max = maxProfit(prices2);

        System.out.println("最大利润"+max);

    }

//    static int maxProfit(int[] prices) {
//        int num;
//        int max=0;
//        for (int i=0;i<prices.length;i++){
//            System.out.println(i+1);
//            if ( i+1<prices.length && prices[i]>=prices[i+1]){
//                continue;
//            }else if (i+1<prices.length && prices[i]<prices[i+1]){
//                num=prices[i+1]-prices[i];
//                max=max+num;
//                System.out.println("买入:"+prices[i]);
//                System.out.println("卖出:"+prices[i+1]);
//            }
//        }
//        return max;
//    }

    static int maxProfit(int[] prices) {
        int num;
        int max=0;
        for (int i=0;i<prices.length-1;i++){
            if (prices[i]>=prices[i+1]){
                continue;
            }else if (prices[i]<prices[i+1]){
                num=prices[i+1]-prices[i];
                max=max+num;
                System.out.println("买入:"+prices[i]);
                System.out.println("卖出:"+prices[i+1]);
            }
        }
        return max;
    }
}
